# coding=utf-8
import download
from bs4 import BeautifulSoup
import config


def findCarDesc(list):
    for carInfo in list:
        html = download.download(config.getConfig("url", "guaziurl") + carInfo['carUrl'], 2)
        soup = BeautifulSoup(html)
        # 基本参数
        c = 0
        for a in soup.find_all('a'):
            aClassName = a.get('class', default=None)
            if None != aClassName and len(aClassName) > 0 and aClassName[0] == 'graybtn':
                c = 1
        if c == 1:
            print "已售出"
        else:
            for k in soup.find_all('table'):
                className = k.get('class', default=None)
                if className[0] == 'param-table':
                    tabjson = dict()
                    a = 0
                    trkey = ""
                    trvalue = ""
                    for td in k.find_all('td'):
                        tdClassName = td.get('class', default=None)
                        a = a + 1
                        if tdClassName[0] == 'td1':
                            trkey = td.string
                        if tdClassName[0] == 'td2':
                            trvalue = td.string
                        if a == 2:
                            tabjson.setdefault(trkey, trvalue)
                            trkey = ""
                            trvalue = ""
                            a = 0
                        print tabjson
            for div in soup.find_all('div'):
                divId = div.get('id', default=None)
                # 图片爬取
                if divId == 'pop-slide':
                    a = 0
                    for picImg in div.find_all("img"):
                        a = a + 1
                        imgUrl = picImg.get('src', default=None)
                        # print imgUrl[:81]
                # 外观内饰检测
                if divId == 'surface':
                    print div
                # 检测报告不包括上边
                divClassName = div.get('class', default=None)
                if divClassName is not None:
                    if len(divClassName) > 2:
                        if divClassName[1] == 'test-packup' and divClassName[2] == 'js-onekind':
                            # print div
                            print "_________________________________"
                    if divClassName[0] == "product-textbox":
                        print div
        break
